package com.ruoyi.project.business.iotchip.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.business.iotchip.mapper.ChipMapper;
import com.ruoyi.project.business.iotchip.entity.Chip;
import com.ruoyi.project.business.iotchip.request.ListChipRequest;
import com.ruoyi.project.business.iotchip.request.AddChipRequest;
import com.ruoyi.project.business.iotchip.response.ChipResponse;
import com.ruoyi.project.business.iotchip.service.IChipService;

/**
 * 芯片设备基本信息管理Service业务层处理
 * 
 * @author ${author}
 * @date 2024-07-19
 */
@Service
public class ChipServiceImpl implements IChipService {
    @Autowired
    private ChipMapper chipMapper;

    /**
     * 查询芯片设备基本信息管理
     * 
     * @return 芯片设备基本信息管理
     */
    @Override
    public Chip selectChipById(Long id) {
        return chipMapper.selectChipById(id);
    }

    /**
     * 查询芯片设备基本信息管理列表
     * 
     * @return 芯片设备基本信息管理
     */
    @Override
    public List<ChipResponse> selectChipList(ListChipRequest request, Long userId, Long tenantId) {
        // TODO request to  param
        Chip param = BeanUtils.copy(request, Chip.class);
        param.setTenantId(tenantId);
        param.setUserId(userId);
        List<Chip> entitis = chipMapper.selectChipList(param);
        List<ChipResponse> resList = BeanUtils.copyList(entitis, ChipResponse.class);
        return resList;
    }

    /**
     * 新增芯片设备基本信息管理
     * 
     * @return 结果
     */
    @Override
    public int insertChip(AddChipRequest request, Long operatorId, Long tenantId) {
        Chip entity = BeanUtils.copy(request, Chip.class);
        entity.setTenantId(tenantId);
        entity.setCreator(operatorId);
        entity.setUserId(operatorId);
        entity.setDeleted(Boolean.FALSE);
        entity.setCreateTime(DateUtils.getNowDate());
        return chipMapper.insertChip(entity);
    }

    /**
     * 修改芯片设备基本信息管理
     * 
     * @return 结果
     */
    @Override
    public int updateChip(Chip entity, Long operatorId, Long tenantId) {
        entity.setUpdateTime(DateUtils.getNowDate());
        entity.setTenantId(tenantId);
        entity.setUpdater(operatorId);
        return chipMapper.updateChip(entity);
    }

    /**
     * 批量删除芯片设备基本信息管理
     * 
     * @return 结果
     */
    @Override
    public int deleteChipByIds(Long[] ids, Long operatorId, Long tenantId) {
        return chipMapper.deleteChipByIds(ids);
    }

    /**
     * 删除芯片设备基本信息管理信息
     * 
     * @return 结果
     */
    @Override
    public int deleteChipById(Long id, Long operatorId, Long tenantId) {
        return chipMapper.deleteChipById(id);
    }
}
